<?php

namespace App\Http\Requests;

use App\Http\ValidateResult;
use Illuminate\Support\Facades\Validator;

trait CustomerRequest 
{
    public static function add_check(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'name' => 'required|max:255',
            'email' => 'required|email|max:255',
            'contact_person' => 'required|max:255',
            'contact_phone' => 'required|max:255',
            'contract' => 'required',
            'account' => 'required|max:255',
            'province_id' => 'nullable|integer',
            'city_id' => 'nullable|integer',
            'district_id' => 'nullable|integer',
            'handle_staff_id' => 'nullable|integer',
            'is_delay' => 'nullable|integer',
            'validity_period' => 'nullable|integer',
        ], [
            'contract.required' => '请上传开户合同',
            'name.required' => '请填写客户名称',
            'name.max' => '客户名称长度不能超过255个字符',
            'email.required' => '请填写邮箱',
            'email.email' => '邮箱格式不正确',
            'email.max' => '邮箱长度不能超过255个字符',
            'contact_person.required' => '请填写联系人',
            'contact_person.max' => '联系人长度不能超过255个字符',
            'contact_phone.required' => '请填写联系电话',
            'contact_phone.max' => '联系电话长度不能超过255个字符',
            'account.required' => '请填写客户端账号',
            'account.max' => '客户端账号长度不能超过255个字符',
        ]);
    

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }

}
